package com.yonyou.cms.epc.controller.graphic;
import com.yonyou.cms.epc.client.dto.graphic.GraphicSystemDTO;
import com.yonyou.cms.epc.service.graphic.GraphicSystemService;
import org.springframework.web.bind.annotation.*;
import com.yonyou.cyx.framework.controller.base.BaseController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import java.util.List;
import java.util.Map;

/**
 *
 * @author yzy
 * @since 2022-06-08
 */
@RestController
@RequestMapping("/graphic/graphicSystem")
public class GraphicSystemController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(GraphicSystemController.class);

    @Autowired
    public GraphicSystemService graphicSystemService;



    /**
     * 分页查询数据
     *
     * @param queryCondition 查询条件
     * @return com.baomidou.mybatisplus.core.metadata.IPage 分页对象
     * @author yzy
     * @since 2022-06-08
     */
    @ResponseBody
    @GetMapping("query")
    @SuppressWarnings("unchecked")
    public IPage<Map<String,Object>> getList (@RequestParam Map<String,Object> queryCondition, @RequestParam
        ("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        logger.debug("执行了分页查询图解系统",queryCondition,currentPage,pageSize);
        Page<Map<String,Object>> page = new Page(currentPage, pageSize);
        return graphicSystemService.selectPageBysql(page, queryCondition);
    }

    /**
     *
     * 批量禁用启用
     * @param ids id集合
     * @param statu 修改后的状态
     * @return
     */
    @ResponseBody
    @PostMapping("/updateStatuByIds")
    @SuppressWarnings("unchecked")
    public boolean updateStatuByIds (@RequestParam String ids,@RequestParam Integer statu) {
        logger.debug("执行了批量启用/禁用",ids,statu);
        return graphicSystemService.updateStatuByIds(ids,statu);
    }

    /**
     * 根据IDs批量删除对象
     *
     * @param ids 需要修改数据的ID集合
     * @author yzy
     * @since 2022-06-08
     */
    @ResponseBody
    @PostMapping(value = "/batch/{ids}")
    public boolean deleteByIds(@PathVariable("ids") String ids){
        logger.debug("执行了批量删除,删除ID:{}",ids);
        graphicSystemService.deleteBatchIds(ids);
        return true;
    }

    /**
     * 进行数据新增
     *
     * @param graphicSystemDto 需要保存的DTO
     * @return Map<String,Object> 返回的数据map
     * @author yzy
     * @since 2022-06-08
     */
    @ResponseBody
    @PostMapping("saveOne")
    @ResponseStatus(HttpStatus.CREATED)
    @SuppressWarnings("unchecked")
    public Map<String,Object> insert(@RequestBody GraphicSystemDTO graphicSystemDto) {
        logger.debug("执行了新增graphicSystemDto:{}",graphicSystemDto);
        return graphicSystemService.insert( graphicSystemDto);
    }

    /**
     * 根据id查询
     *
     * @param systemId 数据主键ID
     * @return  Map<String,Object> 数据对应的map 结构
     * @author yzy
     * @since 2022-06-08
     */
    @ResponseBody
    @GetMapping("selectById")
    @SuppressWarnings("unchecked")
    public Map<String,Object> getById(@RequestParam Integer systemId) {
        logger.debug("执行了根据Id查询systemId:{}",systemId);
        return graphicSystemService.getById(systemId);
    }


    /**
     * 进行数据修改
     *
     * @param id 需要修改数据的ID
     * @param graphicSystemDto 需要保存的DTO
     * @return Map<String,Object> 返回的数据map
     * @author yzy
     * @since 2022-06-08
     */
    @ResponseBody
    @PostMapping(value="/updateById/{id}")
    @ResponseStatus(HttpStatus.CREATED)
    @SuppressWarnings("unchecked")
    public Map<String,Object> updateById(@PathVariable("id") Integer id, @RequestBody GraphicSystemDTO graphicSystemDto) {
        logger.debug("执行了修改graphicSystemDto:{}",graphicSystemDto);
        return graphicSystemService.update(id,graphicSystemDto);
    }

    /**
     * 配件订单批量导入
     *
     * @author sunxh
     * @since 2021-4-23
     */
    @ResponseBody
    @PostMapping("imports")
    @ResponseStatus(HttpStatus.CREATED)
    public Map<String, Object> imports(@RequestBody List<Map<String, Object>> datas) {
        logger.info("批量导入图解系统:{}", datas);
        return graphicSystemService.imports(datas);
    }




    /**
     * 根据id删除对象
     *
     * @param id 需要修改数据的ID
     * @author yzy
     * @since 2022-06-08
     */
    @DeleteMapping(value="/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public boolean deleteById(@PathVariable("id") Integer id){
        logger.debug("删除ID:{}",id);
        graphicSystemService.deleteById(id);
        return true;
    }




}